<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<jsp:include page="../header.jsp">
<jsp:param value="入职管理" name="title"/>
</jsp:include>
<script src="static/js/jquery-1.12.4.js" type="text/javascript"></script>
<script src="semantic/semantic.js" type="text/javascript"></script>
<script src="static/js/student.js" type="text/javascript"></script>
<script type="text/javascript">	
function ajax(params) {

	var xmlhttp;
	//判断XMLHttpRequest是否存在
	if (window.XMLHttpRequest) {
		xmlhttp = new XMLHttpRequest();
	} else {
		xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
	}

	//readystate监听事件
	xmlhttp.onreadystatechange = function() {
		if (xmlhttp.readyState == 4) {
			//输出响应的结果
			console.log("aaaa" + xmlhttp);
			if (params.callback) {
				params.callback(xmlhttp);
			}
		}
	};

	//取出method参数
	var method = params.method ? params.method : "GET";
	var asynch = params.asynch ? params.asynch : true;

	//打开一个连接
	xmlhttp.open(method, params.url, asynch);
	//判断是否POST请求
	if (method.toLowerCase() == 'post') {
		//post请求一定要设置这句话
		xmlhttp.setRequestHeader("Content-Type",
				"application/x-www-form-urlencoded");
	}

	//判断请求是否有参数
	if (params.params) {
		//params.params = {"userName":"张三"，"gender":"男"};
		//转换成userName=张三&gengder=男
		var p = [];
		for (key in params.params) {
			p.push(key + "=" + params.params[key]);
		}
		xmlhttp.send(p.join("&"));
	} else {
		xmlhttp.send(null);
	}
}

//JQuery入口
$(function() {
	$('#stuname').on('blur',
					function() {
						var newstuname = document.getElementById("stuname").value;
						ajax({
							url : "office/add?name=" + newstuname,
							method : "GET",
							callback : function(xmlhttp) {
								var data;
								if (window.JSON) {
									data = JSON.parse(xmlhttp.response);
									if(data == -1){
										$('#hint').html("该生已入职,请重新输入");
										$('#but').hide();
									}
									else if(data>0){
									$('#hint').html("");
									 $('#but').show();
									}
									else{
										$('#hint').html("请输入正确的姓名");
										$('#but').hide();
									}
									var stuid = $(".stuid");
									stuid.val(data);
								} else {
									alert("data");
									data = eval("(" + xmlhttp.response + ")");
								}
								if (data) {
									stuname.innerText = data;
									alert("data");
								}

							}
						});

					});
});
	function add_office(){
		var mo = $("#newoffice");
		mo.modal('show');
	}

	
</script>
</head>
<body>
<div class = "gps">
<a class = "home" href="staff?method=forward">首页</a>
  <i class="right chevron icon divider"></i>
<a href="office/manager">入职管理</a>
</div>
	<div class="searcher" id="officefind">
			<form>
				<div class="ui form">
					<div class="fields">
							<div class="field">
							<label>姓名</label>
					        <input type="text" name="stuname" value="${param.stuname }"> 
					        </div>
					        <div class="field">
							<label>公司</label>
					        <input type="text" name="stucompany" value="${param.stucompany }"> 
					        </div>
					     	<div class="field">
							<label>&nbsp;</label>
							<button class="ui submit button">
							<i class="search icon"></i>
							检索</button>
						</div>
					
					</div>
				</div>
			</form>
		</div>
<div  id="officetab">
	<table class="ui celled table">
			<thead>
				<tr>
					<th colspan="7">入职表</th>
				</tr>
			</thead>
			<tbody>
				<tr>
					<td >姓名</td>
					<td >公司</td>
					<td >试用工资</td>
					<td>正式工资</td>
					<td>入职时间</td>
					<td>
					<a onclick="add_office() " class="ui button"> <i class="icon user"></i>
					新建
				</a></td>
				</tr>
				 <c:forEach items="${officePoList}" var="datas">
					   <tr>
					   <td>${datas.studentName}</td>
						<td>${datas.officeCompany}</td>
						<td>${datas.officeTryMoney}</td>
						<td>${datas.officeFormalMoney}</td>
						<td>${datas.officeTime}</td>
						<td>
						<a  class="ui red button" href ="office/update?oid=${datas.officeId}">
						<i class="edit icon" ></i> 修改
						</a>
						</td>
					</tr>	
				</c:forEach>
			</tbody>
		</table>
	</div>
	<div class="ui right floated pagination menu" id = "officepage">
  	<c:if test="${pageSum > 1 }">  	
			<div class="page">
				<a <c:if test="${nowpage!=1}">href="office/manager?nowpage=1${queryString}"</c:if>
					class="${nowpage == 1?'disable':''}">首页</a> <a
					<c:if test="${nowpage!=1}">href="office/manager?nowpage=${nowpage-1}${queryString}"</c:if>
					class="${nowpage == 1?'disable':''}">上一页</a>
					<span>${nowpage}/${ pageSum} </span> <a
					<c:if test="${nowpage!=pageSum}">href="office/manager?nowpage=${nowpage+1}${queryString}"</c:if>
					class="${nowpage == pageSum?'disable':''}">下一页</a> <a
					<c:if test="${nowpage!=pageSum}">href="office/manager?nowpage=${pageSum }${queryString}"</c:if>
					class="${nowpage == pageSum?'disable':''}">最后一页</a> 
			</div>
		</c:if>
	</div>
	
	<div class="ui modal" id="newoffice">
		<div class="header">新增入职</div>
		<div class="teacher-content">
			<c:set var="test" value="newcoop"></c:set>
			<form id="" method="post" action="office/add">
				<input type="hidden" class="stuid" name="stuid"> 
				<c:set var="test" value=""></c:set>
				<div class="ui input focus">
					<label>学生姓名：</label> <input type="text" id="stuname" name="newstuname" placeholder="姓名">
					<span id ="hint" ></span>
				</div>
				<br>
				<div class="ui input focus">
					<label>入职公司：</label> <input type="text" placeholder="公司" name="officeCompany" required="required">
				</div>
				<br>
				<div class="ui input focus">
					<label>试用薪资：</label> <input type="text" name="officeTryMoney" placeholder="试用薪资" required="required">
				</div>
				<br>
				<div class="ui input focus">
					<label>正式薪资：</label> <input type="text" name="officeFormalMoney" placeholder="正式薪资" required="required">
				</div>
				<br>
				<div class="ui input focus">
					<label>入职时间：</label> <input type="text" placeholder="入职时间" name="officeTime" onfocus="HS_setDate(this)" required="required">
				</div>
				<br>
				<div class="actions">
				<div class="ui black deny button" onclick = "nofollow()">取消新增</div>
				<button  id="but">
					<div class="ui positive right labeled icon button">
						确认新增 <i class="checkmark icon"></i>
					</div>
				</button>
				</div>
			</form>
		</div>
	</div>
</body>
</html>